SQL DEFAULT Constraint
SQL DEFAULT Constraint:
The DEFAULT constraint is used to set a default value for a column.
The default value will be added to all new records, if no other value is specified
SQL DEFAULT on CREATE TABLE:
CREATE TABLE Persons (ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
SQL DEFAULT on ALTER TABLE:
ALTER TABLE Persons ALTER City SET DEFAULT 'Sandnes';
DROP a DEFAULT Constraint:
ALTER TABLE Persons ALTER City DROP DEFAULT;